import axios from 'axios';
import qs from 'qs';

const baseUrl = "http://116.62.147.89:3333/";
//跨域请求
axios.defaults.withCredentials = true

const httpServer = (opts, data) => {
  let httpDefaultOpts = {
    method: opts.method,
    url: baseUrl + opts.url,
    async: opts.async,
    cache: opts.cache,
    contentType: opts.contentType,
    // timeout: 3000,
    data: data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'X-Requested-With': 'XMLHttpRequest',
    }
  }

  let promise = new Promise((resolve,reject)=>{
    axios(httpDefaultOpts).then(
      res => {
        resolve(res)
      }
    ).catch(error => {
      reject(error)
    })
  })

  return promise
}
export default httpServer
